﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ChinaDynastyTours.Controls;
using ChinaDynastyTours.Helpers;

namespace ChinaDynastyTours.Views
{
    public partial class TravelOrderServiceForm : DevExpress.XtraEditors.XtraForm
    {
        //输入参数
        public int _TourGroupScheduleID { get; set; }//行程计划ID
        public string _ProviderID { get; set; }//如存在预订的宾馆供应商，则传进来

        //输出参数
        public string ReturnProviderId { get; set; }
        public string ReturnProviderName { get; set; }
        public string ReturnContractPath { get; set; }
        public string ReturnServiceName { get; set; }
        public string ReturnCityName { get; set; }

        public TravelOrderServiceForm(string desCityName)
        {
            InitializeComponent();
        
            tbCityName.EditValue = desCityName;
        }

        private void LoadData()
        {
            travelGridControl.DataSource = BaseInfoCtrl.GetProviderData(new ProviderTypeEnum[] { ProviderTypeEnum.旅行社 }, CN2PYHelper.CapitalCovert(tbCityName.Text), CN2PYHelper.CapitalCovert(tbProviderName.Text));
        }

        private void HotelOrderServiceForm_Load(object sender, EventArgs e)
        {
            LoadData();

        }
        private void travelGridView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e.FocusedRowHandle < 0) return;

            string providerId = travelGridView.GetDataRow(e.FocusedRowHandle)["ProviderID"].ToString();
            if (string.IsNullOrEmpty(providerId)) return;
            travelServiceGridControl.DataSource = ServiceInfoCtrl.GetTravelAgentServiceData(providerId);
        }

        private void travelServiceGridView_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            //双击服务表格，将单价写入文本框中
            if (e.Clicks == 2)
                btnOk.PerformClick();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            ReturnProviderId = travelGridView.GetDataRow(travelGridView.FocusedRowHandle)["ProviderID"].ToString();
            ReturnProviderName = travelGridView.GetDataRow(travelGridView.FocusedRowHandle)["ProviderName"].ToString();
            ReturnContractPath=travelGridView.GetDataRow(travelGridView.FocusedRowHandle)["Contact"].ToString();
            ReturnCityName = travelGridView.GetDataRow(travelGridView.FocusedRowHandle)["City"].ToString();
            
            if (travelServiceGridView.FocusedRowHandle < 0 || chkSelectedService.Checked == true)
                ReturnServiceName = "";
            else
                ReturnServiceName = travelServiceGridView.GetRowCellValue(travelServiceGridView.FocusedRowHandle, "FeaturesRoom").ToString();
        }
        private void TextBox_TextChanged(object sender, EventArgs e)
        {
            LoadData();
        }

        private void chkSelectedService_CheckedChanged(object sender, EventArgs e)
        {
            travelServiceGridControl.Enabled = !chkSelectedService.Checked;
        }
    }
}
